package com.zhuang.learn.junit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by zhuanglei on 15/3/25.
 */
public class UserInputServicesImpl implements UserInputServices {
    @Override
    public String checkInputLength(String inputContent) {
        if (inputContent.length() > 6 ){
            return "input length bigger than six";
        }else if (inputContent.length() < 6) {
            return "input length less than 6";
        }else{
            return "OK";
        }

    }

    @Override
    public String checkInputContent(String inputContent) {

        boolean result = true;
        for (int i = 0; i < inputContent.length(); i++) {
            if (!Character.isDigit(inputContent.charAt(i))) {
                result = false;
                break;
            }
        }

        if (result) {
            return "all digital";
        }else {
            return "not all of digital";
        }
    }

    @Override
    public String readUserInput(InputStream inputStream) {
        InputStreamReader is_reader = new InputStreamReader(System.in);
        try {
            return new BufferedReader(is_reader).readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "error";

        }
    }
}
